import React from 'react'
import * as actionCreates from './store/actionCreates'
import { connect } from 'react-redux'
import {
    HomeWrapper,
    HomeLeft,
    HomeRight,
    BackTop
} from './style'

//引入每个模块的小组件
import List from './components/List'
import Recommend from './components/Recommend'
import Writer from './components/Writer'

class Home extends React.Component{

    handleBackTop() {
        //他不需要this 所以就不用绑定了
        window.scrollTo(0, 0);
    }
    render(){
        return(
           <HomeWrapper>
               <HomeLeft>
                   <img alt='' className='banner-img' src='//upload.jianshu.io/admin_banners/web_images/4582/2db83cc6f08d13c2f83002238ca32b784266c4fb.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/1250/h/540' />
                   <List />
               </HomeLeft>
               <HomeRight>
                   <Recommend />
                   <Writer />
               </HomeRight>
               <BackTop
               onClick={this.handleBackTop}
               >
                    <i className="iconfont">&#xe600;</i>
               </BackTop>
           </HomeWrapper>
        )
    }

    componentDidMount() {
       
            // 怎么在这里把action dispatch出去
            this.props.changeHomeData()
     
    }
    
}


const mapDispatch =(dispatch)=>({
    changeHomeData(){
        dispatch(actionCreates.getListInfo())
    }
})

export default connect(null, mapDispatch)(Home)